<template>
  <div class="news">
    <div class="topheader">
      <div class="title">NEWS</div>
    </div>
    <div class="contentbox">
      <div class="listwarp">
        <div class="item" v-for="items in item" :key="items.id">
          <img
            @click="jumpdetail(items.id)"
            class="leftImg"
            :src="items.cover"
            alt=""
          />
          <div @click="jumpdetail(items.id)" class="info">
            <div class="title">{{ items.tittle }}</div>
            <div class="subtitle">{{ items.summary }}</div>
            <div class="footerInfo">
              <img src="/image/news/timer.png" alt="" />
              <span>{{ items.releaseTime.split(" ")[0] }}</span>
              <img src="/image/news/user.png" alt="" />
              <span>{{ items.publisher }}</span>
            </div>
          </div>
        </div>
        <pageNation
          v-if="item.length"
          :total="totalCount"
          @changeCurrent="changeCurrent"
        />
      </div>
      <div class="rightlist">
        <div class="search">
          <input v-model="search" placeholder="搜索内容" />
          <button @click="searchInfo">
            <img src="/image/news/search.png" alt="" />
          </button>
        </div>
        <div class="listtitle">
          <img src="/image/news/map.png" alt="" />
          <span>公司新闻</span>
        </div>
        <div class="listwarpz">
          <div
            @click="changeChecked(item)"
            v-for="item in list2"
            :key="item.english"
            :class="[checked === item.english ? 'active item' : 'item']"
          >
            <div class="lefttitle">{{ item.chinese }}</div>
            <div class="righttitle">{{ item.english }}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import pageNation from "@/components/pageNation";
import axios from "axios";
export default {
  components: {
    pageNation
  },
  async mounted() {
    let item = [];
    let totalCount = 0;
    try {
      let { data } = await axios.post(
        "/officialwebsiteapi/informations/apiGetInformations",
        {
          keyword: "",
          page: {
            maxResultCount: 0,
            pageNo: 0,
            pageSize: 5,
            skipCount: 0
          },
          type: 0
        }
      );
      if (data.code === 1000) {
        this.item = data.data.items.items;
        this.totalCount = data.data.items.totalCount;
      }
    } catch (error) {
      // context.$msg.error("网络错误")
    }
  },
  data() {
    return {
      item: [],
      totalCount: 0,
      search: "",
      list2: [
        {
          chinese: "公司动态>>",
          english: "Company news",
          type: 0
        },
        {
          chinese: "行业资讯>>",
          english: "Industry information",
          type: 1
        },
        {
          chinese: "媒体信息>>",
          english: "Media",
          type: 2
        },
        {
          chinese: "企业公告>>",
          english: "Announcement",
          type: 3
        },
        {
          chinese: "企业影像>>",
          english: "Image",
          type: 4
        },
        {
          chinese: "图片新闻>>",
          english: "Pictures",
          type: 5
        },
        {
          chinese: "员工风采>>",
          english: "Employee",
          type: 6
        }
      ],
      checked: "Company news",
      page: {
        maxResultCount: 0,
        pageNo: 0,
        pageSize: 5,
        skipCount: 0
      },
      type: 0
    };
  },
  methods: {
    searchInfo() {
      this.getdata();
    },
    changeChecked(res) {
      this.checked = res.english;
      this.type = res.type;
      this.getdata();
    },
    changeCurrent(res) {
      this.page.pageNo = res;
      this.getdata();
    },
    jumpdetail(id) {
      this.$router.push({ path: "/newsdetail", query: { id } });
    },
    getdata() {
      axios
        .post("/officialwebsiteapi/informations/apiGetInformations", {
          keyword: String(this.search).trim(),
          page: this.page,
          type: this.type
        })
        .then(res => {
          if (res.data.code === 1000) {
            this.item = res.data.data.items.items;
            this.totalCount = res.data.data.items.totalCount;
          } else {
            this.$msg.error(res.data.msg);
          }
        })
        .catch(err => {
          this.$msg.error(err.message);
        });
    }
  }
};
</script>
<style lang="scss" scoped>
.topheader {
  width: 100%;
  height: 746px;
  background: url("http://syg-photo.oss-cn-shanghai.aliyuncs.com/yingdin/photo/bg.png-1593655030000") no-repeat;
  background-size: 100% 100%;
  position: relative;
  .title {
    position: absolute;
    top: 381px;
    left: 276px;
    font-size: 157px;
    font-weight: bold;
    color: rgba(255, 255, 255, 1);
    line-height: 242px;
    text-align: center;
    width: 556px;
    background: url("/image/news/newsbg.png") no-repeat;
  }
}
.contentbox {
  padding-bottom: 36px;
  width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  margin-top: 69px;
}
.listwarp {
  box-sizing: border-box;
  padding: 24px 31px 0 31px;
  width: 813px;
  background-color: #f9f9f9;
  .item {
    cursor: pointer;
    margin-bottom: 25px;
    display: flex;
    .leftImg {
      max-width: 301px;
      max-height: 199px;
      min-width: 301px;
      min-height: 199px;
    }
    .info {
      margin-left: 29px;
    }
    .title {
      font-size: 21px;
      color: #3f3f3f;
    }
    .subtitle {
      margin-top: 20px;
      font-size: 16px;
      color: #3f3f3f;
      padding-bottom: 48px;
    }
    .footerInfo {
      background: url("/image/news/triangle.png") no-repeat;
      background-position: 100% 100%;
      width: 421px;
      padding: 18px 0 12px;
      border-top: 3px solid #e6e6e6;
      border-bottom: 3px solid #e6e6e6;
      font-size: 18px;
      color: #949494;
      display: flex;
      img:first-of-type {
        width: 22px;
        height: 22px;
        margin-right: 6px;
      }
      img:last-of-type {
        margin-left: 38px;
        width: 22px;
        height: 22px;
      }
      span:last-of-type {
        margin-left: 6px;
      }
    }
  }
}
.rightlist {
  .listwarpz {
    margin-top: 16px;
  }
  .search {
    display: flex;
    align-items: center;
    input {
      width: 286px;
      height: 54px;
      background-color: #f7f7f7;
      border: solid 2px #e6e6e6;
      outline: none;
      text-indent: 24px;
    }
    button {
      cursor: pointer;
      width: 50px;
      height: 56px;
      background-color: #f34540;
      border: solid 2px #df3732;
      display: flex;
      justify-content: center;
      align-items: center;
    }
  }
  .listtitle {
    display: flex;
    align-items: flex-end;
    margin-top: 50px;
    padding-bottom: 7px;
    border-bottom: 3px solid #e6e6e6;
    img {
      width: 44px;
      height: 47px;
    }
    span {
      font-size: 24px;
      color: #3f3f3f;
    }
  }
  .item {
    cursor: pointer;
    margin-bottom: 6px;
    display: flex;
    justify-content: space-between;
    padding: 0 20px 0 25px;
    line-height: 54px;
    .lefttitle {
      font-size: 21px;
      color: #3f3f3f;
    }
    .righttitle {
      font-size: 17px;
      color: #404040;
    }
  }
  .active {
    background-color: #303f9f;
    .lefttitle {
      color: #ffffff;
    }
    .righttitle {
      color: #ffffff;
    }
  }
}
</style>
